<#assign ctx=request.contextPath />
<#macro add url>
<body>
<div class="layui-container" style="margin-top:12px;">
	<div class="layui-row">
		<#nested>
	</div>
</div>
</body>
<script type="text/javascript">
layui.use(['dtree','form', 'appJs','layer'], function() {
		var $ = layui.$;
        var form = layui.form
            , layer = layui.layer
            , app = layui.appJs
            ,dtree = layui.dtree;

        if(typeof verifies != "undefined") {
        	form.verify(verifies);
        }

        $("form").bind("submit", function (e) {
            var data = {};
            $(this).serializeArray().map(function (x) {
                data[x.name] = x.value;
            });
            submitData(app.fields($('.layui-form')))
            return false;
        })
        //监听提交
        form.on('submit(save)', function (data) {
        	submitData(data.field);
            return false;
        });
        $("#cls_btn").bind('click',function(){
        	closeInfo();
        });

        function closeInfo() {
        	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        	parent.layer.close(index); //再执行关闭
        }

        function submitData(data) {
        	$.ajax({
        		type:'post',
        		url:'${url}',
        		data:data,
        		traditional:true,
        		success:function(data){
        			 if (data.code == '0') {
                         alert(data.msg);
                         closeInfo();
                     } else {
                         layer.msg(data.code + ':' + data.msg, {anim: 6, time: 1000});
                     }
        		}
        	});
        }

        window.loadData = function(form,url,id) {
			app.fillForm(form,url,id);
        }
	});
</script>
</#macro>
<#macro edit url>
<body>
<div class="layui-container" style="margin-top:12px;">
	<div class="layui-row">
		<#nested>
	</div>
</div>
</body>
<script type="text/javascript">
function disableEdit() {
	layui.use('appJs',function(){
		var $ = layui.$;
		$(".layui-form").find('input,select,textarea').attr("disabled","disabled");
		$(".layui-form").find(".layui-btn").parents('.layui-form-item').hide();
		$(".layui-form").find(".layui-btn").hide();
		$(".layui-form").append('<div class="layui-form-item">'
				+'<div class="layui-input-block">'
				+'<a class="layui-btn layui-btn-primary" id="modify_btn" onclick="enableEdit();">修改</a>'
				+'</div>'
				+'</div>');
	})
}
function enableEdit() {
	layui.use('appJs',function(){
		var $ = layui.$;
		$(".layui-form").find('input,select,textarea').removeAttr("disabled");
		$("#modify_btn").parent().parent().remove();
		$(".layui-btn").parents('.layui-form-item').show();
		$(".layui-btn").show();
	})
}
</script>
<script type="text/javascript">
layui.use(['dtree','form', 'appJs','layer'], function() {
		var $ = layui.$;
        var form = layui.form
            , layer = layui.layer
            , app = layui.appJs
            ,dtree = layui.dtree;

        form.verify({
            name: function (value) {
                if (value.length < 2) {
                    return '角色名至少得2个字';
                }
            }
        });

        $("form").bind("submit", function (e) {
            var data = {};
            $(this).serializeArray().map(function (x) {
                data[x.name] = x.value;
            });
            submitData(app.fields($('.layui-form')))
            return false;
        })
        //监听提交
        form.on('submit(save)', function (data) {
        	submitData(data.field);
            return false;
        });
        $("#cls_btn").bind('click',function(){
        	closeInfo();
        });

        function closeInfo() {
        	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        	parent.layer.close(index); //再执行关闭
        }

        function submitData(data) {
        	$.ajax({
        		type:'post',
        		url:'${url}',
        		data:data,
        		traditional:true,
        		success:function(data){
        			 if (data.code == '0') {
                         alert(data.msg);
                         closeInfo();
                     } else {
                         layer.msg(data.code + ':' + data.msg, {anim: 6, time: 1000});
                     }
        		}
        	});
        }
	});
</script>
</#macro>